<?php
class Base_model extends CI_Model{
    const VERSION = '`upgrade`.`version`';
    const PRODUCT = '`upgrade`.`product`';
    public function __construct()
    {
        parent::__construct();
    }

    public function getAllChannels() {
        $sql = "SELECT productname, GROUP_CONCAT(DISTINCT(channel)) as channels FROM ".INET_STATICS." GROUP BY productname;";
        $result = $this -> db -> query($sql) -> result('array');
        if(!$result) return false;
        $data = array();
        foreach($result as $item) {
            $key = 'p_' . $item['productname'];
            $data[$key]['channels'] = explode(',' , $item['channels']);
        }
        return $data;
    }
    public function getAllProducts() {
        $sql = "SELECT productname FROM ".INET_STATICS." GROUP BY productname;";
        $result = $this -> db -> query($sql) -> result('array');
        if(!$result) return false;
        
        if($result) {
            return $result;
        }
    
        return array();
    }

    public function getVersion() {
        $sql = 'SELECT * FROM '.UPGRADE_VERSION ." LIMIT 1000";
        return $this -> db -> query($sql) -> result();
    }

    public function getProduct() {
        $sql = 'SELECT * FROM '.UPGRADE_PRODUCT." LIMIT 1000";
        return $this -> db -> query($sql) -> result();
    }
}
